var uploadzdj = function( ajdik ) {
	$("#loading2_"+ajdik)
	.ajaxStart(function(){
		$(this).show();
	})
	.ajaxComplete(function(){
		$(this).hide();
	});

	$.ajaxFileUpload
	(
		{
			url:baseUrl + '/cpproducts/upload',
			secureuri:false,
			fileElementId:'zdjecieId_'+ajdik,
			dataType: 'json',
			success: function (data, status)
			{

				if(typeof(data.error) != 'undefined')
				{
					if(data.error != '')
					{
						console.error('error: ' + data.error);
					} else {
						$('#image_' + ajdik +'').val(data.msg);
						$('#photoContainer2_'+ajdik).html('<img src="'+photoUrl+data.msg+'">');
					}
				}
			},
			error: function (data, status, e)
			{

				console.error('blad: ' + e );
				console.info( data );
			}
		}
	)
	return false;
};
$(document).ready(function(){
	if( !logged ) {
		window.setTimeout(function(){

			var settings = {
				tl: { radius: 10 },
				tr: { radius: 10 },
				bl: { radius: 10 },
				br: { radius: 10 },
				antiAlias: true,
				autoPad: true
			};
	
			$('.login-form form').corner(settings).attr({ id : 'loginform' });
			
			settings = {
					tl: { radius: 2 },
					tr: { radius: 2 },
					bl: { radius: 2 },
					br: { radius: 2 }
				};
			$('.login-form form p.submit a.button').corner(settings).attr({ id : 'submit' });
			$('.login-form').css({
				display: 'block',
				opacity: 0
			}).animate({
				opacity: 1
			});

			$('a#submit').click(function(){
				$('#loginform').submit();
			});
		},100);
	} else {
		var instance;

		var settings = {
			tl: { radius: 2 },
			tr: { radius: 2 },
			bl: { radius: 2 },
			br: { radius: 2 }
		};
		window.setTimeout(function(){
			$('a.button').corner(settings);
		}, 200 );

		var opercomm = $('.opercomm');
		opercomm.corner(settings).attr({ id : 'operout' });
		window.setTimeout( function(){
			
			$( '#operout' ).parent().animate({
				height: '0px',
				marginTop: '0px',
				paddingTop: '0px',
				marginBottom: '0px',
				paddingBottom: '0px',
				opacity: 0
			}, 1000, null, function(){
				$(this).css({ display: 'none' });
			});
			
		}, 5000 );
		
		var player = $( '<div></div>' );
		player.css({
			display: 'none',
			width: '200px',
			height: '200px',
			position: 'absolute',
			top: '0px',
			left: '0px'
		}).hover(function(){
			$(this).css({ display: 'block' });
			instance.attr( 'class', ( instance.attr( 'class' ) == 'act' ) ? 'act' : 'hv' );
		}, function(){
			$(this).css({ display: 'none' });
			instance.attr( 'class', ( instance.attr( 'class' ) == 'act' ) ? 'act' : null );
		});
		
		$(document.body).append( player );

		
		var menu = $( 'ul.menu li' );
		menu.hover(function(){
			instance = $(this);
			
			var spans = instance.find( 'div' );
			if( spans.length ) {
				
				var color = {
					background : ( instance.attr( 'class' ) == 'act' ) ? '#cacaca' : '#EFEFEF',
					border : ( instance.attr( 'class' ) == 'act' ) ? '#999' : '#DFDFDF',
					className : ( instance.attr( 'class' ) == 'act' ) ? 'act' : 'hv'
				};
				
				var cl = ( color.className == 'act' ) ? 'act' : null;
				
				var bounds = instance.bounds();
				
				var elHeight = 28;
				instance.attr( 'class', color.className );
				player.css({
					top: parseInt( bounds.top + elHeight ) + 'px',
					left: bounds.left + 'px',
					background: color.background,
					borderLeft: '6px solid ' + color.border,
					display: 'block',
					height: parseInt( 30 * spans.length ) + 'px'
				})
				player.empty();
				for( var i = 0, len = spans.length; i < len; i++ ) {
					player.append( $( spans[i] ).clone().css({ display: 'block' }) );
				}
				
			}
		},function(){
			instance = $( this );
			var cl = ( instance.attr( 'class' ) == 'act' ) ? 'act' : null;
			player.css({ display: 'none' });	
			instance.attr( 'class', cl );
		});
	}
});